#pragma once
#include<iostream>
#include"log.hpp"
#include<cstdlib>
#include<ctime>

using std::cout;
using std::endl;

enum cause
{
    normal=0,
    zero_kill=1,
};

class Task
{
public:
    log L;

    //使用rand函数生成随机数的任务，不需要手动传参
    // Task(int x,int y,char op)
    // :a(x),b(y),op_(op),code_(normal)
    // {}

    Task()
    {
        code_=normal;
        a=random();
        b=random();
        switch (random()%5)
        {
            case 0:
                {
                    op_='+';
                    break;
                }
            case 1:
                {
                    op_='-';
                    break;
                }
            case 2:
                {
                    op_='*';
                    break;
                }
            case 3:
                {
                    op_='/';
                    if(b==0)
                        code_=zero_kill;
                    break;
                }
            case 4:
                {
                    op_='%';
                    if(b==0)
                        code_=zero_kill;
                    break;
                }
        }
    }

    Task(int r1,int r2,char op)
    :a(r1)
    ,b(r2)
    ,op_(op)
    {
        if(op_=='/'||op_=='%')
        {
            if(b==0)
                code_=zero_kill;
        }
    }

    //生成随机数
    int random()
    {   
        int tmp=rand()%1000;
        return tmp;
    }

    void deal()
    {
        switch (op_)
        {
            case '+':
                cout<< a << "+" << b << "=" <<a+b<<"      code="<<code_<<endl;break;
            case '-':
               cout<< a << "-" << b << "="  <<a-b<<"      code="<<code_<<endl;break;
            case '*':
                cout<< a << "*" << b << "=" <<a*b<<"      code="<<code_<<endl;break;
            case '/':
                {
                    cout<< a << "/" << b << "=" <<a/b<<"      code="<<code_<<endl;
                    code_=zero_kill;
                    break;
                }
            case '%':
               cout<< a << "%" << b << "=" <<a%b<<"      code="<<code_<<endl;
                break;
            default:    
                L(warn,"当前输入的符号有误");
        }
    }

    void operator()()    //运算符重载
    {
        deal();
    }

private:
    int a;
    int b;
    char op_;
    int code_;  //判断结果是否可信，默认为0；
};